﻿#include <stdio.h> 
#include <mpi.h> 
#include <math.h> 
#include <iostream>
using namespace std;
int main(int argc, char** argv)
{	
	int myid, numprocs,i,N=100;
	double local = 0.0, init, x;	
	MPI_Init(&argc, &argv);
	MPI_Comm_rank(MPI_COMM_WORLD, &myid);
	MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
	--numprocs;
	if (myid == 0)
		cin >> N;
	for (i = myid; i < N; i = i + numprocs)
	{
		x = sqrt(i*(i + 1));
		local = local + x;
	}
	MPI_Reduce(&local, &init,1,MPI_DOUBLE,MPI_SUM,0,MPI_COMM_WORLD );
	if (myid == 0)
	{
		cout << local << endl;
	}
	MPI_Finalize();
}
